// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-04-05 12:14
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.DateTrain;

import java.util.HashSet;
import java.util.Set;

public class CountPrimeSetBits {
    /**
     * 计算质数个计算置位
     * 枚举整形32位以内的质数
     */
    public int countPrimeSetBits(int left, int right) {
        int ans = 0;
        Set<Integer> prime = new HashSet<>();
        prime.add(2);
        prime.add(3);
        prime.add(5);
        prime.add(7);
        prime.add(11);
        prime.add(13);
        prime.add(17);
        prime.add(19);
        prime.add(23);
        prime.add(29);
        prime.add(31);
        for (int i = left; i <= right; i++) {
            if (prime.contains(Integer.bitCount(i))) {
                ans++;
            }
        }
        return ans;
    }
}
